{extend name="Public:base"/}

{block name="main"}
{load href="__STATIC__/MyDate/WdatePicker.js"/}
{load href="__JS__/jquery.colorpicker.js"/}
{load href="__JS__/Sortable.min.js"/}
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/neditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/neditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/lang/zh-cn/zh-cn.js"></script>

<div class="box-info">
    <form id="myform" action="{:U($model_name.'/add')}" method="post">
        <input type="hidden" name="TOKEN" value="{:session('TOKEN')}">

        {volist name="fields" id="r"}
        {if condition="!empty($r['status'])"}
        <div class="form-group row">
            <label class="col-md-2 col-form-label text-right">
                {if condition="$r['required']"}<font color="red">*</font>{/if}{$r.name}
            </label>
            <div class="col-md-8" id="box_{$r['field']}">
                {if condition="$r['type'] == 'images'"}
                <?php $parseData = $form->images($r);?>
                <div class="card">
                    <div class="card-header">最多同时可以上传<span class="text-danger">{$r['setup']['upload_maxnum']}</span>张
                        <div class="pull-right">
                            <a class="btn btn-sm btn-info" href="javascript:swfupload('{$r['field']}', '{$parseData['cenpic_auth']}', up_images);">图片上传</a></div>
                    </div>
                    <div id="{$r['field']}_images" class="card-body imagesList">
                    </div>
                </div>
                <script>
                    Sortable.create({$r['field']}_images, { handle: "img", animation: 150});
                </script>

                {else/}
                {$form->getform($r['type'], $r, $value='')}
                {/if}
            </div>
        </div>
        {/if}
        {/volist}

        <div class="form-actions">
            <input type="submit" value="提交" class="btn btn-primary" />
            <input type="reset" value="重置" class="btn btn-primary"/>
        </div>
    </form>
</div>

{/block}


{block name="script"}

<script type="text/javascript">
    String.prototype.replaceAll = function(s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    }
    $(function() {
        $('#myform').on('click', '.datalist .add', function() {
            var $el = $(this).parent().parent();
            var $datalist = $('#myform .datalist');
            var num = $datalist.data('num');
            $el.after(rowStr.replaceAll('{num}', num));
            num++;
            $datalist.data('num',num);
        }).on('click', '.datalist .remove', function() {
            var $el = $(this).parent().parent();
            $el.remove();
        });
    });
    $(document).ready(function() {
        $('#myform').ajaxForm({
            success:  complete,  // post-submit callback
            dataType: 'json'
        });
    });

    function complete(data){
        if (data.status === 1) {

            layer.confirm(data.info, {
                icon:1,
                btn: ['继续发布内容','返回列表'] //按钮
            }, function(){
                window.location.href = "{:U($model_name.'/add')}";
                return false;
            }, function(){
                window.location.href = "{$Think.cookie.__forward__}";
                return true;
            });
        } else {
            layer.msg(data.info, {icon: 2});
        }
    }
</script>
{/block}